package web;

import java.util.List;
import java.util.Map;

import vo.Element;
import vo.User;
import business.ElementService;
import business.UserService;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Preparable;

@SuppressWarnings("unchecked")
public class ElementAction implements Preparable {
	private ElementService service;
	private UserService userService;
	private List<Element> elements;
	private User curUser;

	public String listElement() {
		this.elements = service.getAllElements();
		return Action.SUCCESS;
	}

	public String addElement() {
		service.addElement("hello xxx");
		return listElement();
	}

	public List<Element> getElements() {
		return this.elements;
	}

	public void prepare() throws Exception {
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		String username = (String) session.get("username");
		curUser = userService.getByLoginName(username);
	}

	public void setElementService(ElementService service) {
		this.service = service;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public User getCurUser() {
		return curUser;
	}

	public void setCurUser(User curUser) {
		this.curUser = curUser;
	}

}